Home:ALL Converter>Change and move MongoDB data directory in Windows

Change and move MongoDB data directory in Windows

Ask Time:2021-04-18T16:21:20         Author:Ding Li

Json Formatter

The drive for holding my Mongo data is running out of space (data directory: D:\mongo\data). So I decided to move the data directory to another drive that has a larger space (intended directory: F:\mongodata\data).

I learned that I could just copy D:\mongo\data to F:\mongodata\data and modify the dbPath in mongod.cfg to dbPath: F:\mongodata\data (the log is still path: D:\mongo\log\mongod.log). However when I try to connect to MongoDB via MongoDB Compass Community, I get the following error,

connect ECONNREFUSED 127.0.0.1:27017

The command line returns this error,

C:\Users\liding>mongo
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect@src/mongo/shell/mongo.js:362:17
@(connect):2:6
exception: connect failed
exiting with code 1

I don't know if it is the problem with Windows service since I installed Windows service right after installing MongoDB on my PC. So I followed this by modifying the regedit and restarted my computer. The problem was still there.

I also tried mongod --dbpath "F:\mongodata\data" in cmd following this. It appeared to be working.

{"t":{"$date":"2021-04-18T16:16:35.933+08:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-04-18T16:16:35.935+08:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-04-18T16:16:35.935+08:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2021-04-18T16:16:35.936+08:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":5292,"port":27017,"dbPath":"F:/mongodata/data","architecture":"64-bit","host":"lidingoffice"}}
{"t":{"$date":"2021-04-18T16:16:35.936+08:00"},"s":"I",  "c":"CONTROL",  "id":23398,   "ctx":"initandlisten","msg":"Target operating system minimum version","attr":{"targetMinOS":"Windows 7/Windows Server 2008 R2"}}
{"t":{"$date":"2021-04-18T16:16:35.936+08:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":[],"allocator":"tcmalloc","environment":{"distmod":"windows","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2021-04-18T16:16:35.936+08:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Microsoft Windows 10","version":"10.0 (build 18363)"}}}
{"t":{"$date":"2021-04-18T16:16:35.936+08:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"storage":{"dbPath":"F:\\mongodata\\data"}}}}
{"t":{"$date":"2021-04-18T16:16:35.937+08:00"},"s":"W",  "c":"STORAGE",  "id":22271,   "ctx":"initandlisten","msg":"Detected unclean shutdown - Lock file is not empty","attr":{"lockFile":"F:\\mongodata\\data\\mongod.lock"}}
{"t":{"$date":"2021-04-18T16:16:35.937+08:00"},"s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"F:/mongodata/data","storageEngine":"wiredTiger"}}
{"t":{"$date":"2021-04-18T16:16:35.937+08:00"},"s":"W",  "c":"STORAGE",  "id":22302,   "ctx":"initandlisten","msg":"Recovering data from the last clean checkpoint."}
{"t":{"$date":"2021-04-18T16:16:35.937+08:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=15762M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
{"t":{"$date":"2021-04-18T16:16:36.243+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1618733796:243547][5292:140737312022176], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 5962 through 5963"}}
{"t":{"$date":"2021-04-18T16:16:36.287+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1618733796:286397][5292:140737312022176], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 5963 through 5963"}}
{"t":{"$date":"2021-04-18T16:16:36.332+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1618733796:332303][5292:140737312022176], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Main recovery loop: starting at 5962/2304 to 5963/256"}}
{"t":{"$date":"2021-04-18T16:16:36.333+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1618733796:332303][5292:140737312022176], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 5962 through 5963"}}
{"t":{"$date":"2021-04-18T16:16:36.418+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1618733796:418251][5292:140737312022176], file:sizeStorer.wt, txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 5963 through 5963"}}
{"t":{"$date":"2021-04-18T16:16:36.454+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1618733796:454386][5292:140737312022176], file:sizeStorer.wt, txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"}}
{"t":{"$date":"2021-04-18T16:16:36.569+08:00"},"s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":632}}
{"t":{"$date":"2021-04-18T16:16:36.570+08:00"},"s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
{"t":{"$date":"2021-04-18T16:16:36.592+08:00"},"s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"}
{"t":{"$date":"2021-04-18T16:16:36.641+08:00"},"s":"W",  "c":"CONTROL",  "id":22120,   "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]}
{"t":{"$date":"2021-04-18T16:16:36.642+08:00"},"s":"W",  "c":"CONTROL",  "id":22140,   "ctx":"initandlisten","msg":"This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning","tags":["startupWarnings"]}
{"t":{"$date":"2021-04-18T16:16:36.668+08:00"},"s":"I",  "c":"STORAGE",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
{"t":{"$date":"2021-04-18T16:16:36.775+08:00"},"s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"F:/mongodata/data/diagnostic.data"}}
{"t":{"$date":"2021-04-18T16:16:36.778+08:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"127.0.0.1"}}
{"t":{"$date":"2021-04-18T16:16:36.778+08:00"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
{"t":{"$date":"2021-04-18T16:16:37.004+08:00"},"s":"I",  "c":"FTDC",     "id":20631,   "ctx":"ftdc","msg":"Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost","attr":{"error":{"code":0,"codeName":"OK"}}}

However, after a few seconds, the connection would disconnect automatically and throw some "WiredTiger error" (part of the error is as follows),

{"t":{"$date":"2021-04-18T16:17:36.778+08:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"TTLMonitor","msg":"WiredTiger error","attr":{"error":0,"message":"[1618733856:777592][5292:140737312022176], file:index-6--2848807291971628139.wt, WT_SESSION.open_cursor: __wt_block_read_off, 283: index-6--2848807291971628139.wt: read checksum error for 4096B block at offset 4096: block header checksum of 0xebf13864 doesn't match expected checksum of 0x6b102582"}}
{"t":{"$date":"2021-04-18T16:17:36.778+08:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"TTLMonitor","msg":"WiredTiger error","attr":{"error":0,"message":"[1618733856:778335][5292:140737312022176], file:index-6--2848807291971628139.wt, WT_SESSION.open_cursor: __wt_bm_corrupt_dump, 135: {4096, 4096, 0x6b102582}: (chunk 1 of 4): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 36 00 00 00 0e 00 00 00 01 00 00 01 00 10 00 00 64 38 f1 eb 01 00 00 00 e2 f5 1a 80 cf c0 cf c0 df c0 cf c0 80 81 e4 01 6a 39 1c e2 0f c0 00 00 00 00 00 00 c4 72 65 6e 63 72 79 70 74 69 6f 6e 3d 28 6b 65 79 69 64 3d 2c 6e 61 6d 65 3d 29 2c 62 6c 6f 63 6b 5f 6d 65 74 61 64 61 74 61 5f 65 6e 63 72 79 70 74 65 64 3d 66 61 6c 73 65 2c 62 6c 6f 63 6b 5f 6d 65 74 61 64 61 74 61 3d 5b 61 63 63 65 73 73 5f 70 61 74 74 65 72 6e 5f 68 69 6e 74 3d 6e 6f 6e 65 2c 61 6c 6c 6f 63 61 74 69 6f 6e 5f 73 69 7a 65 3d 34 4b 42 2c 61 70 70 5f 6d 65 74 61 64 61 74 61 3d 28 66 6f 72 6d 61 74 56 65 72 73 69 6f 6e 3d 38 29 2c 61 73 73 65 72 74 3d 28 63 6f 6d 6d 69 74 5f 74 69 6d 65 73 74 61 6d 70 3d 6e 6f 6e 65 2c 64 75 72 61 62 6c 65 5f 74 69 6d 65 73 74 61 6d 70 3d 6e 6f 6e 65 2c 72 65 61 64 5f 74 69 6d 65 73 74 61 6d 70 3d 6e 6f 6e 65 29 2c 62 6c 6f 63 6b 5f 61 6c 6c 6f 63 61 74 69 6f 6e 3d 62 65 73 74 2c 62 6c 6f 63 6b 5f 63 6f 6d 70 72 65 73 73 6f 72 3d 2c 63 61 63 68 65 5f 72 65 73 69 64 65 6e 74 3d 66 61 6c 73 65 2c 63 68 65 63 6b 73 75 6d 3d 6f 6e 2c 63 6f 6c 6c 61 74 6f 72 3d 2c 63 6f 6c 75 6d 6e 73 3d 2c 64 69 63 74 69 6f 6e 61 72 79 3d 30 2c 65 6e 63 72 79 70 74 69 6f 6e 3d 28 6b 65 79 69 64 3d 2c 6e 61 6d 65 3d 29 2c 66 6f 72 6d 61 74 3d 62 74 72 65 65 2c 68 75 66 66 6d 61 6e 5f 6b 65 79 3d 2c 68 75 66 66 6d 61 6e 5f 76 61 6c 75 65 3d 2c 69 64 3d 31 30 2c 69 67 6e 6f 72 65 5f 69 6e 5f 6d 65 6d 6f 72 79 5f 63 61 63 68 65 5f 73 69 7a 65 3d 66 61 6c 73 65 2c 69 6e 74 65 72 6e 61 6c 5f 69 74 65 6d 5f 6d 61 78 3d 30 2c 69 6e 74 65 72 6e 61 6c 5f 6b 65 79 5f 6d 61 78 3d 30 2c 69 6e 74 65 72 6e 61 6c 5f 6b 65 79 5f 74 72 75 6e 63 61 74 65 3d 74 72 75 65 2c 69 6e 74 65 72 6e 61 6c 5f 70 61 67 65 5f 6d 61 78 3d 31 36 6b 2c 6b 65 79 5f 66 6f 72 6d 61 74 3d 75 2c 6b 65 79 5f 67 61 70 3d 31 30 2c 6c 65 61 66 5f 69 74 65 6d 5f 6d 61 78 3d 30 2c 6c 65 61 66 5f 6b 65 79 5f 6d 61 78 3d 30 2c 6c 65 61 66 5f 70 61 67 65 5f 6d 61 78 3d 31 36 6b 2c 6c 65 61 66 5f 76 61 6c 75 65 5f 6d 61 78 3d 30 2c 6c 6f 67 3d 28 65 6e 61 62 6c 65 64 3d 74 72 75 65 29 2c 6d 65 6d 6f 72 79 5f 70 61 67 65 5f 69 6d 61 67 65 5f 6d 61 78 3d 30 2c 6d 65 6d 6f 72 79 5f 70 61 67 65 5f 6d 61 78 3d 35 4d 42 2c 6f 73 5f 63 61 63 68 65 5f 64 69 72 74 79 5f 6d 61 78 3d 30 2c 6f 73 5f 63 61 63 68 65 5f 6d 61 78 3d 30 2c 70 72 65 66 69 78 5f 63 6f 6d 70 72 65 73 73 69 6f 6e 3d 74 72 75 65 2c 70 72 65 66 69 78 5f 63 6f 6d 70 72 65 73 73 69 6f 6e 5f 6d 69 6e 3d 34 2c 73 70 6c 69 74 5f 64 65 65 70 65 6e 5f 6d 69 6e 5f 63 68 69 6c 64 3d 30 2c 73 70 6c 69 74 5f 64 65 65 70 65 6e 5f 70 65 72 5f 63 68 69 6c 64 3d 30 2c 73 70 6c 69 74 5f 70 63 74 3d 39 30 2c 76 61 6c 75 65 5f 66 6f 72 6d 61 74 3d 75 2c 76 65 72 73 69 6f 6e 3d 28 6d 61 6a 6f 72 3d 31 2c 6d 69 6e 6f 72 3d 31 29 2c 63 68 65 63 6b 70 6f 69 6e 74 3d 28 57 69 72 65 64 54 69 67 65 72 43 68 65 63 6b 70 6f 69 6e 74 2e 32 38 33 38 37 35 3d 28 61 64 64 72 3d 22 30 31 38 30 38 30 38 30 38 30 38 30 38 30 38 31 38 31 65 34 31 37 32 64 34 33 36 31 38 30 38 30 38 30 65 32 30 66 63 30 38 30 "}}
{"t":{"$date":"2021-04-18T15:57:51.396+08:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"TTLMonitor","msg":"WiredTiger error","attr":{"error":-31802,"message":"[1618732671:395950][17832:140737312022176], file:index-6--2848807291971628139.wt, WT_SESSION.open_cursor: __wt_block_read_off, 292: index-6--2848807291971628139.wt: fatal read error: WT_ERROR: non-specific WiredTiger error"}}
{"t":{"$date":"2021-04-18T15:57:51.397+08:00"},"s":"E",  "c":"STORAGE",  "id":22435,   "ctx":"TTLMonitor","msg":"WiredTiger error","attr":{"error":-31804,"message":"[1618732671:396947][17832:140737312022176], file:index-6--2848807291971628139.wt, WT_SESSION.open_cursor: __wt_block_read_off, 292: the process must exit and restart: WT_PANIC: WiredTiger library panic"}}
{"t":{"$date":"2021-04-18T15:57:51.398+08:00"},"s":"F",  "c":"-",        "id":23089,   "ctx":"TTLMonitor","msg":"Fatal assertion","attr":{"msgid":50853,"file":"src\\mongo\\db\\storage\\wiredtiger\\wiredtiger_util.cpp","line":446}}
{"t":{"$date":"2021-04-18T15:57:51.404+08:00"},"s":"F",  "c":"-",        "id":23090,   "ctx":"TTLMonitor","msg":"\n\n***aborting after fassert() failure\n\n"}
{"t":{"$date":"2021-04-18T15:57:51.405+08:00"},"s":"F",  "c":"CONTROL",  "id":4757800, "ctx":"TTLMonitor","msg":"Writing fatal message","attr":{"message":"Got signal: 22 (SIGABRT).\n"}}

Any clue of how to fix this problem? Thanks!

Author:Ding Li,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/67146498/change-and-move-mongodb-data-directory-in-windows
yy